<template>
	<el-container v-if="isAlready">
		<el-header  style="padding-top: 0px;padding-bottom: 0px;height: 60px;background-color: rgb(249, 249, 249);border-bottom: 1px solid #e6e6e6;">
			<div class="left-panel">
				<div style="margin-left: -5px;float: left;">
					<img class="topblockimg" src="img/pandian-icon.png"/>
				</div>
				<template v-if="isCreate">
					<label style="font-size: 14px;margin-left: 5px;">新增盘点单</label>
				</template>
				<template v-else>
					<label style="font-size: 14px;margin-left: 5px;">编辑盘点单</label>
				</template>
			</div>
			<div class="right-panel">
				<fsButton ref="button" plain size="small" :buttons="buttons" @clickHandler="buttonHandler"></fsButton>
			</div>
		</el-header>
		<div style="background-color: #fff;">
			<el-descriptions class="margin-top stockdescriptions" :column="3" border>
				<el-descriptions-item label="盘点单编号:"  label-class-name="checklabelwidth">{{documentData.code}}</el-descriptions-item>
				<template v-if="documentId">
					<el-descriptions-item label="盘点部门:" label-class-name="checklabelwidth"><ex-label :key="documentData.orgId" code="SysOrganization" :value="documentData.orgId"/></el-descriptions-item>
					<el-descriptions-item label="制定人:" label-class-name="checklabelwidth"><ex-label :key="documentData.createUser" code="SysUser" :value="documentData.createUser"/></el-descriptions-item>
					<el-descriptions-item label="制定日期:" label-class-name="checklabelwidth"><ex-label :key="documentData.createTime" format code="DATETIME" :value="documentData.createTime"/></el-descriptions-item>
				</template>
				<template v-else>
					<el-descriptions-item label="盘点部门:"  label-class-name="checklabelwidth"><ex-selector :params="{ids:this.filterDeptIds}" :model="form" prop="orgId" code="SysOrganization" :isicon="true"/></el-descriptions-item>
					<el-descriptions-item label="制定人:"  label-class-name="checklabelwidth" >{{loginUser.userName}}</el-descriptions-item>
					<el-descriptions-item label="制定日期:"  label-class-name="checklabelwidth">{{currentTime}}</el-descriptions-item>
				</template>
				<el-descriptions-item label="盘点任务:"  label-class-name="checklabelwidth">{{taskData.name}}</el-descriptions-item>
				<el-descriptions-item label-class-name="labelClassName" label="*盘点单名称" ><el-input v-model="documentData.name"></el-input> </el-descriptions-item>
<!--							<el-descriptions-item label-class-name="labelClassName" label="*盘点人:" v-model="checkDocument.checkUser"><ex-selector code="SysUser" :model="form" prop="checkDocument.checkUser"></ex-selector></el-descriptions-item>-->
				<!--el-descriptions-item label="描述:"  label-class-name="checklabelwidth" ><el-input type="textarea" v-model="documentData.description"></el-input></el-descriptions-item-->
			</el-descriptions>
		</div>
		<el-main style="padding: 0px;margin-top: 5px;">
			<div style="height: 100%;background-color: #fff;">
				<el-container>
					<el-header style="width: 98%;padding-top: 0px;padding-bottom: 0px;height: 50px;border: 1px rgba(0, 0, 0, .08) solid;
					margin-left: 1%;background-color: rgb(249, 249, 249);">
						<div class="left-panel">
							<label style="font-size: 14px; width: 100px;">盘点单明细</label>
							<template v-if="documentId">
								<sc-select-filter :data="filterData" :label-width=80 @on-change="tabChange">
								</sc-select-filter>
							</template>
						</div>
						<div class="right-panel">
							<ex-search v-if="searches" ref="search" :searches="searches" @searchOk="searchHandler" default-code="assetCode" placeholder="请输入盘点单编码" :fixedParam=fixedParams :initParams="searchParams"></ex-search>
						</div>
					</el-header>
					<el-main class="nopadding">
						<ex-table id="checkDetailTable" :auto-refresh="false" ref="table" :columns="columns" :url="this.$API.asset.checkDetailApi.page.url" :refs="this.$refs" search="search" @columnClick="columnClickHandler"></ex-table>
					</el-main>
				</el-container>
			</div>
			<data-card ref="dataCard"></data-card>
			<selector ref="selector" :ids="ids" :data="resultDatas" @success="userSelectHandler"></selector>
			<asset-selecter ref="assetSelecter" :ids="assetIds" @success="assetSelectHandler"></asset-selecter>
		</el-main>
	</el-container>
	<view-dialog ref="viewDialog"/>
	<import-check-detail ref="importCheckDetail" @success="refreshPage"></import-check-detail>
</template>

<script>
import ExTable from "@/components/exTable/index.vue";
import ExSearch from "@/components/exSearch/index.vue";
import ExImage from "@/components/exImage/index.vue";
import ExTreeNavigation from "@/components/exSearchTree/index.vue";
import ExSearchTree from "@/components/exSearchTree/index.vue";
import ExLabel from "@/components/exLabel/index.vue";
import Selector from "@/components/exSelector/selecter.vue";
import ExSelector from "@/components/exSelector/index.vue";
import tool from "@/utils/tool";
import viewDialog from "@/views/asset/check/checkDocument/view.vue";
import AssetSelecter from "@/views/asset/asset/asset-selecter.vue";
import DataCard from "@/views/asset/card/card.vue";
import ImportCheckDetail from "@/views/asset/check/checkDocument/importCheckDetail.vue";
import moment from "moment";
import router from "@/router";
import useTabs from "@/utils/useTabs";
import scSelectFilterCheck from "@/components/scSelectFilterCheck/index.vue";
import {uuid} from "@tinymce/tinymce-vue/lib/es2015/main/ts/Utils";

export default {
	name: '盘点单编辑',
	components: {
		scSelectFilterCheck,
		ImportCheckDetail,
		DataCard,
		AssetSelecter,
		ExSelector,
		ExLabel,
		ExImage,
		ExSearchTree,
		ExTreeNavigation,
		ExSearch,
		ExTable,
		Selector,
		viewDialog
	},
	data() {
		return {
			loginUser : tool.current.user(),
			loading: false,
			currentTime: moment(new Date()).format("YYYY-MM-DD HH:mm:ss"),
			dialog: {
				save: false,
				permission: false,
			},
			form: {
				id: "",
				orgId: "",
				userName: "",
				userCode: "",
				loginName: "",
				mobile: "",
				email: "",
				checkUserId:"",
			},
			apiObj: [],
			buttons: [
				{name: "添加明细", icon: "el-icon-plus", click: "addAsset", permission: "checkDetailAdd"},
				{name: "删除", icon: "el-icon-delete",type: "info", click: "del", permission: "checkDetailDel"},
				{name: "导入", icon: "el-icon-upload",type: "info", click: "upload", permission: "importantDetail"},
				{name: "保存", icon: "el-icon-check",type: "info", click: "saveNotAuto", permission: "documentSave"},
				{name: "清空", icon: "el-icon-close",type: "info", click: "delete", permission: "removeAllDetail"},
				{name: "盘点单详情", icon: "el-icon-search",type: "info", click: "viewData", permission: ""},
				{name: "盘点人变更", icon: "el-icon-edit",type: "info", click: "changeUser", permission: "checkUser"},
			],
			searches: null,
			columns: [
                {code: "attachFiles", name: "拍照信息",fixedValue:"拍照信息", width:"90",formatter: "IMAGE"},
				{code: "checkResult", name: "盘点结果", width:"100",formatter:"DICT",key: "CHECK_RESULT"},
				{code: "isPhoto", name: "是否必须拍照", width:"110",formatter:"DICT",key: "IS_PHOTO"},
				{code: "assetCode", name: "资产编码", width:"160",click:"show1"},
				{code: "ncCode", name: "财务编码", width:"170"},
				{code: "assetCategory", name: "资产类别", width:"250",formatter:"DICT",key: "FamsAssetCategory"},
                {code: "assetName", name: "资产名称", width:"120"},
				{code: "financialCode", name: "类型",width: "85", formatter: function(row){
						if(row.ncCode){
							return "账内";
						}
						return "账外";
					}},
                {code: "model", name: "规格型号", width:"120"},
                {code: "originalValue", name: "资产原值", width:"120"},
                {code: "netValue", name: "资产净值", width:"120"},
                {code: "usingUser", name: "使用人", width:"100",formatter: "DICT",key: "SysUser"},
				{code: "usingOrg", name: "使用部门", width:"200",formatter: "DICT",key: "SysOrganization"},
                {code: "realityUsingUser", name: "实际使用人", width:"120",formatter: "DICT",key: "SysUser"},
				{code: "checkPosition", name: "盘点位置", width:"100",formatter: "DICT",key: "FamsPosition"},
				{code: "assetPosition", name: "资产位置", width:"100",formatter: "DICT",key: "FamsPosition"},
                {code: "assetCount", name: "数量", width:"85"},
                {code: "checkAccount", name: "盘点数量", width:"100"},
                {code: "checkUser", name: "盘点人", width:"100",formatter: "DICT",key: "SysUser"},
                {code: "realityCheckUser", name: "实际盘点人", width:"110",formatter: "DICT",key: "SysUser"},
				{code: "checkDate", name: "盘点时间", width:"150",formatter: "DATE"},
				{code: "checkDescription", name: "盘点备注说明", width:"200"},
			],
			filterData: [
				{
					title: "【盘点结果汇总】",
					key: "checkResult",
					multiple: false,
					options: [
						{
							label: "全部(0)",
							value: ""
						},
						{
							label: "未盘(0)",
							value: "0"
						},
						{
							label: "正常(0)",
							value: "1"
						},
						{
							label: "异常(0)",
							value: "2"
						},
						{
							label: "盘盈(0)",
							value: "3"
						},
						{
							label: "盘亏(0)",
							value: "4"
						},
					]
				},
			],
			parentLevelCode:"",
			checkTaskId:"",
			fixedParams: {
			},
			readDeptIds: this.$TOOL.current.readDeptIds(),
			manageDeptIds: this.$TOOL.current.manageDeptIds(),
			checkResult:"",
			searchParams:{},
			assetIds:[],
			isAlready: false,
			isCreate: false,
			taskData: {},
			documentData: {},
			filterAssetIds: [],
			taskId: '',
			documentId: '',
			assetCategoryIds: [],
			checkDeptIds: [],
			filterDeptIds: [],
			ids: [],
			resultDatas: {},
			updateDetailIds:[],
			minioServerUrl: '',
		}
	},
	created() {
		//如果是通过跳转过来的，标签的名称设置为跳转后的标题
		let route = router.currentRoute.value;
		if (route.meta) {
			this.title = route.meta.title;
		}
		let routeParams = this.$store.state.routeParams[this.$route.params.key];
		if (routeParams) {
			if (routeParams.title) {
				useTabs.setTitle(routeParams.title);
				document.title = routeParams.title;
			}
			if (routeParams.fixedParams) {
				if (routeParams.fixedParams.taskId) {
					this.taskId = routeParams.fixedParams.taskId;
					this.fixedParams.taskId = routeParams.fixedParams.taskId;
				}
				if (routeParams.fixedParams.documentId) {
					this.documentId = routeParams.fixedParams.documentId;
					this.searchParams.documentId = routeParams.fixedParams.documentId;
				}else{
					this.isCreate = '1';
				}
			}
			this.fixedParams.readDeptIds = this.readDeptIds;
			if (routeParams.searchParams) {
				Object.assign(this.searchParams, routeParams.searchParams);
			}
			this.getQueryDataAndRelDataByQueryDto();
			this.searches = [
				{type: "select", name: "盘点结果", code: "checkResult", placeholder: "请选择盘点结果", dictCode:'CHECK_RESULT'},
				{type: "selector", name: "盘点人", code: "createUser", placeholder: "请选择盘点人", dictCode:'SysUser'},
				{type: "input", name: "资产编码", code: "assetCode", placeholder: "请输入资产编码"},
				{type: "input", name: "财务编码", code: "ncCode", placeholder: "请输入财务编码"},
				{type: "input", name: "资产名称", code: "assetName", placeholder: "请输入资产名称"},
				{type: "tree-select", name: "资产类别", code: "assetCategoryIds", placeholder: "请选择资产类别", dictCode:'FamsAssetCategory',checkStrictly:true,multiple:true,priKey:true,permissionData:this.assetCategoryIds,dataPermissionProcess:true},
				{type: "select", name: "资产类型", code: "assetType", placeholder: "请选择资产类型", dictCode:'ASSET_TYPE'},
				{type: "tree-select", name: "资产位置", code: "assetPositionIds", placeholder: "请选择资产位置", dictCode:'FamsPosition',checkStrictly:true,multiple:true,priKey:true},
			];
			this.isAlready = true;

		}
	},
	async mounted() {
		this.minioServerUrl = await this.$TOOL.minioServerUrl();
		if (this.documentId) {
			let queryParamst = {};
			queryParamst.taskId = this.taskId;
			queryParamst.documentId = this.documentId;
			this.fixedParams.queryUser = this.loginUser.id;
			queryParamst.queryUser = this.loginUser.id;
			queryParamst.readDeptIds = this.readDeptIds;
			await this.getCountData(queryParamst);
			this.$nextTick(() => {
				this.searchHandler();
			});
		}

	},
	beforeCreate() {

	},
	methods: {
		buttonHandler(index, name) {
			this.$options.methods[name](this, index);
		},
		async getQueryDataAndRelDataByQueryDto() {
			let queryDtoData = {};
			queryDtoData.id = this.documentId;
			queryDtoData.taskId = this.taskId;
			this.assetCategoryIds = [];
			this.taskData = {};
			this.documentData = {};
			this.checkDeptIds = [];
			this.filterAssetIds = [];
			let rsp = await this.$API.asset.checkDocumentApi.getQueryDataAndRelDataByQueryDto.post(queryDtoData);
			if (rsp.code === 2000 && rsp.data) {
				if (rsp.data.assetCheckTask) {
					this.taskData = rsp.data.assetCheckTask;
				}
				if (rsp.data.assetCheckDocument) {
					this.documentData = rsp.data.assetCheckDocument;
				}
				if (rsp.data.manageCheckDeptIds) {
					this.checkDeptIds = rsp.data.manageCheckDeptIds;
					if(!this.documentId){
						this.filterDeptIds = this.manageDeptIds.filter(item => {
							return this.checkDeptIds.includes(item);
						});
					}
				}
				if (rsp.data.assetCategoryIds) {
					this.assetCategoryIds = rsp.data.assetCategoryIds;
				}
				// if (rsp.data.filterAssetIds){
				// 	this.filterAssetIds = rsp.data.filterAssetIds;
				// }
			}
		},
		searchHandler() {
			let queryParams = {}
			if(this.documentId){
				queryParams.documentId = this.documentId;
			}else{
				queryParams.isCreate = '1';
			}
			this.$refs.table.refresh(queryParams);
		},
		columnClickHandler(name,data){
			this.$options.methods[name](this, data);
		},
		//查看
		async show1(_this, row,index) {
			_this.$refs.button.loading(index, true);
			let assetCategoryData = await _this.$cache.data.loadAssetCategory(row.assetCategory);
			try {
				let entity = {cardId: assetCategoryData.assetCardId, _editFlag: false}
				_this.$nextTick(async () => {
					let assetRsp = await _this.$API.asset.asset.findById.post({id: row.assetId});
					if (assetRsp.code === 2000 && assetRsp.data) {
						_this.$refs.button.loading(index, false);
						_this.$refs.dataCard.open(Object.assign(entity, assetRsp.data));
					} else {
						_this.$refs.button.loading(index, false);
						_this.$message.message("未查询到资产信息");
					}
				});
			} catch {
				_this.$refs.button.loading(index, false);
			}
		},
		delete(_this,index){
			_this.$confirm(`是否清空该盘点单下的所有盘点明细?`, '警告', {
				type: 'warning'
			}).then(async () => {
				_this.$refs.button.loading(index, true);
				let rsp = await _this.$API.asset.checkDetailApi.delete.post({documentId: _this.documentId});
				if (rsp.code === 2000) {
					// if(rsp.data){
					// 	let result = _this.filterAssetIds.filter(item => !rsp.data.includes(item));
					// 	_this.filterAssetIds = result;
					// }
					_this.$emit('success');
					_this.$message.success(_this.$t("code." + rsp.code));
					_this.refreshPage();
				} else {
					_this.$message.warning(rsp.message)
				}
				_this.$refs.button.loading(index, false);
			}).catch(() => {
				_this.$refs.button.loading(index, false);
			});
		},
		async saveNotAuto(_this, index) {
			let entityData = {}
			if (!_this.documentId) {
				//如果没有盘点单id，先判断必填字段，然后保存盘点单信息
				if (!_this.documentData.name) {
					_this.$message.error("请填写盘点单名称");
					return;
				}
				if(!_this.form.orgId){
					_this.$message.error("请选择盘点部门");
					return;
				}
				entityData.createUser = _this.loginUser.id;
				entityData.createTime = _this.currentTime;
				entityData.orgId = _this.form.orgId;

			} else {
				entityData.id = _this.documentId;
			}
			entityData.name = _this.documentData.name;
			entityData.description = _this.documentData.description;
			entityData.taskId = _this.taskId;
			_this.$refs.button.loading(index, true);
			let rsp = await _this.$API.asset.checkDocumentApi.saveCheckDocumentNotAuto.post(entityData);
			if (rsp.code === 2000 && rsp.data) {
				_this.$emit('success');
				if(_this.documentId){
					_this.$message.success(_this.$t("code." + rsp.code));
					useTabs.refresh();
				}else{
					useTabs.close();
					_this.searchCheckDocumentEdit(rsp.data,_this.taskId);

				}
			}else {
				_this.$message.warning(rsp.message)
			}
			_this.$refs.button.loading(index, false);

		},
		async getCountData(queryParams) {
			let rsp = await this.$API.asset.checkDetailApi.countResultByQueryDto.post(queryParams);
			if (rsp.code === 2000) {
				if (rsp.data != null) {
					let optionsData = [
						{
							label: "全部(" + rsp.data.totalCount + ")",
							value: ""
						},
						{
							label: "未盘(" + rsp.data.nodoCount + ")",
							value: "0"
						},
						{
							label: "正常(" + rsp.data.normalCount + ")",
							value: "1"
						},
						{
							label: "异常(" + rsp.data.errCount + ")",
							value: "2"
						},
						{
							label: "盘盈(" + rsp.data.surplusCount + ")",
							value: "3"
						},
						{
							label: "盘亏(" + rsp.data.lossCount + ")",
							value: "4"
						},
					];
					Object.assign(this.filterData[0].options, optionsData);
				}
			}
		},
		async save(_this, index) {
			let saveData = {};
			if (!_this.documentId) {
				//如果没有盘点单id，先判断必填字段，然后保存盘点单信息
				if (!_this.documentName) {
					_this.$message.error("请填写盘点单名称");
					return;
				}
				saveData.createUser = _this.loginUser.id;
				saveData.createTime = _this.currentTime;
				saveData.orgId = _this.loginUser.orgId;

			} else {
				saveData.id = _this.documentData.id;
			}
			saveData.name = _this.documentName;
			saveData.description = _this.documentData.description;
			saveData.taskId = _this.taskId;
			_this.$refs.button.loading(index, true);
			try {
				let rsp = await _this.$API.asset.checkDocumentApi.save.post(saveData);
				if (rsp.code === 2000) {
					_this.$emit('success');
					_this.documentData = rsp.data;
					_this.$message.success("处理成功");
				} else {
					_this.$message.warning(rsp.message)
				}
				_this.$refs.button.loading(index, false);
			} catch {
				_this.$refs.button.loading(index, false);
			}
		},
		//添加
		async addAsset(_this) {
			_this.assetIds = [];
			if (!_this.documentData.name) {
				_this.$message.error("请填写盘点单名称");
				return;
			}
			if(!_this.documentData.id){
				_this.$message.error("请先保存再添加明细");
				return;
			}
			let usingDepartmentIds = [];
			if(_this.documentData){
				if(_this.documentData.orgId){
					usingDepartmentIds.push(_this.documentData.orgId);
				}
			}
			let params = {
				assetCategoryIds:_this.assetCategoryIds,
				usingDepartmentIds: usingDepartmentIds,
				isDocumentCheck: true,
			}
			if(_this.taskData){
				if(_this.taskData.excludeAssetStatus){
					params.excludeStatus = _this.taskData.excludeAssetStatus.split(',');
				}
				if(_this.taskData.excludeDocumentTypes){
					params.excludeDocumentTypes = _this.taskData.excludeDocumentTypes.split(',');
				}
				params.checkTaskId = _this.taskData.id;

				if(_this.taskData.isIncludeInvisible === '0'){
					params.financialTypes = ['in'];
				}
			}
			_this.$nextTick(() => {
				_this.$refs.assetSelecter.open(params);
			})
			return true;
		},

    async assetSelectHandler(index) {
		this.$refs.button.loading(index, true);
		let checkDetail = {
			taskId: this.taskId,
			documentId: this.documentId,
			documentCode: this.documentCode,
			assetIds: this.assetIds,
		}
		let rsp = await this.$API.asset.checkDetailApi.add.post(checkDetail);
		if(rsp.code===2000){
			// this.assetIds.forEach((item)=>{
			// 	this.filterAssetIds.push(item);
			// })
			this.$message.success(this.$t("code." + rsp.code));
			this.$store.dispatch("commit", rsp.data.entityName);
			this.refreshPage();
		} else {
			this.$message.warning(rsp.message)
		}
		this.$refs.button.loading(index, false);
	},
		//变更盘点人
		changeUser(_this,index){
			let entity = {
				selector: 'SysUser',
				// manageDeptIds: row.orgId
			};
			_this.$refs.button.loading(index, true);
			let selections = _this.$refs.table.selections();
			if (selections.length === 0) {
				_this.$confirm(`是否全部资产进行盘点人变更?`, '警告', {
					type: 'warning'
				}).then(() => {
					_this.$refs.selector.open(entity);
					_this.$refs.button.loading(index, false);
				}).catch(() => {
					_this.$refs.button.loading(index, false);
				});
			}else{
				_this.$refs.button.loading(index, true);
				_this.updateDetailIds = [];
				for (let index = 0; index < selections.length; index++) {
					const element = selections[index];
					_this.updateDetailIds.push(element.id);
				}
				_this.$refs.selector.open(entity);
				_this.$refs.button.loading(index, false);
			}
		},
		//变更管理员回传方法
		async userSelectHandler() {
			if (this.resultDatas && this.resultDatas.id) {
				let selections = this.$refs.table.selections();
				let ids = [];
				if (selections.length !== 0) {
					for (let index = 0; index < selections.length; index++) {
						const element = selections[index];
						ids.push(element.id);
					}
				}
				this.$refs.button.loading(true);
				try {
					let dataParams = {
						checkUser: this.resultDatas.id,
						documentId: this.documentId,
						ids: ids,
					}
					let rsp = await this.$API.asset.checkDetailApi.updateCheckUser.post(dataParams);
					if (rsp.code === 2000) {
						this.searchHandler();
					}
					this.$refs.button.loading(false);
				} catch {
					this.$refs.button.loading(false);
				}
			}
		},
		//编辑
		edit(_this,index) {
			_this.$refs.button.loading(index, true);
			let selections = _this.$refs.table.selections();
			if (selections.length === 0) {
				_this.$confirm(`是否对全部盘点明细进行盘点人变更?`, '警告', {
					type: 'warning'
				}).then(() => {
					_this.$refs.userSecter.openSelector({});
					_this.$refs.button.loading(index, false);
				}).catch(() => {
					_this.$refs.button.loading(index, false);
				});
			}else{
				_this.$refs.button.loading(index, true);
				_this.updateUser = [];
				for (let index = 0; index < selections.length; index++) {
					const element = selections[index];
					_this.updateUser.push(element.id);
				}
				_this.$refs.userSecter.openSelector();
				_this.$refs.button.loading(index, false);
			}

		},
		//刷新页面
		refreshPage() {
			this.searchHandler();
			let queryParamst = {};
			queryParamst.taskId = this.taskId;
			queryParamst.documentId = this.documentId;
			queryParamst.queryUser = this.loginUser.id;
			queryParamst.readDeptIds = this.readDeptIds;
			this.getCountData(queryParamst);
		},
		//批量删除
		del(_this, index) {
			let selections = _this.$refs.table.selections();
			if (selections.length === 0) {
				_this.$message.warning(_this.$t("common.please_select_data"));
				return;
			}
			_this.$confirm(`确定删除选中的 ${selections.length} 盘点明细吗？`, '警告', {
				type: 'warning'
			}).then(async () => {
				_this.$refs.button.loading(index, true);
				let delarray = [];
				let removeAssetIds = []
				for (let index = 0; index < selections.length; index++) {
					const element = selections[index];
					delarray.push(element.id);
					removeAssetIds.push(element.assetId);
				}
				let rsp = await _this.$API.asset.checkDetailApi.deleteByIds.post(delarray);
				if (rsp.code === 2000) {
					_this.$message.success(_this.$t("code."+rsp.code));
					// if(removeAssetIds.length){
					// 	let result = _this.filterAssetIds.filter(item => !removeAssetIds.includes(item));
					// 	_this.filterAssetIds = result;
					// }
					_this.refreshPage();
					_this.$refs.button.loading(index, false);
				} else {
					_this.$message.warning(rsp.message)
				}

			}).catch(() => {
				_this.$refs.button.loading(index, false);
			});
		},
		//导入盘点明细资产信息
		upload(_this,index){
			if(_this.documentId){
				try {
					let checkDocument = {
						id: _this.documentId,
						taskId: _this.taskId,
						createUser: _this.loginUser.id,
						createTime: _this.currentTime,
					}
					_this.$refs.button.loading(index, true);
					_this.$nextTick(() => {
						_this.$refs.importCheckDetail.open(checkDocument);
					});
					_this.$refs.button.loading(index, false);
				} catch  {
					_this.$refs.button.loading(index, false);
				}
			}else{
				_this.$message.error("请先保存盘点单信息");
			}
		},
		//查看盘点单详情
		viewData(_this,index){
			_this.$refs.button.loading(index, true);
			if(_this.documentId){
				_this.$nextTick(() => {
					let entity = {
						taskId: _this.taskData.id,
						taskName: _this.taskData.name,
						taskCode: _this.taskData.code,
						documentId: _this.documentData.documentId,
						documentCode: _this.documentData.code,
						documentName: _this.documentData.name,
						startDate: _this.taskData.startDate,
						endDate: _this.taskData.endDate,
						checkManageUsers: _this.documentData.checkManageUser,
						documentCreateTime: _this.documentData.createTime,
						documentCreateUser: _this.documentData.createUser,
						documentDescription: _this.documentData.description,
						documentOrgId: _this.documentData.orgId,
					}
					_this.$refs.viewDialog.open(entity);
					_this.$refs.button.loading(index, false);
				})
			}else{
				_this.$refs.button.loading(index, true);
				_this.$message.error("请先保存盘点单信息");
			}
		},
		//标签切换
		async tabChange(name){
			name.pathCode = this.parentLevelCode
			await this.$refs.table.refresh(name);
		},
		searchCheckDocumentEdit(checkDocumentData,taskId) {
			let title = '';
			if(checkDocumentData){
				title = "编辑"+checkDocumentData.code+"盘点单";
			}else{
				title = "新增盘点单";
			}
			//跳转到搜索台账页面
			let fromRouteId = this.$TOOL.crypto.MD5(this.$route.path);//当前页面的路由地址
			let key = '';
			if(checkDocumentData){
				key = this.$TOOL.crypto.MD5(checkDocumentData.code);//可以做为key的关键字段或内容
			}else{
				key = this.$TOOL.crypto.MD5(taskId+uuid("s"));//可以做为key的关键字段或内容
			}
			//设置搜索参数
			let routeParams = {
				id: key,
				title: title,
				fixedParams:{
				},//固定搜索参数，打开页面后，用户通过搜索界面的清空按钮无法清除
			};
			if(checkDocumentData){
				routeParams.fixedParams = {
					taskId:taskId,
					documentId:checkDocumentData.id,
				}
			}else{
				routeParams.fixedParams = {
					taskId:taskId,
				}
			}
			this.$store.dispatch("addRouteParams", routeParams);
			this.$router.push({
				name: "toCheckDocumentAdd",
				params: {fromRouteId: fromRouteId, key: key}
			});
		},
	}
}

</script>
<style scoped>
:deep(.labelClassName){
	color: red !important;
}

:deep(.el-descriptions__body .el-descriptions__table.is-bordered .el-descriptions__cell){
	padding: 2px 11px;
}
:deep(.checklabelwidth){
	width:100px;
}

</style>
